import Vue from 'vue'
import App from './App.vue'
import VueRouter from 'vue-router'
import store from './store'
import routes from './router'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import './public-path'
import './mock'
Vue.config.productionTip = false

Vue.use(VueRouter)
Vue.use(ElementUI)
// new Vue({
//   render: h => h(App),
// }).$mount('#app')

let router = null;
let instance = null;

//single-spa的生命周期函数
export async function bootstrap(data) {
  console.log(data)
  // Array.isArray(fns) && fns.map(i => {
  //   Vue.prototype[i.name] = i
  // });
}

export async function mount(data) {
  console.log('执行app1mount')
  console.log(data)
  router = new VueRouter({
    base: window.__POWERED_BY_QIANKUN__ ? "/layout/app3" : "/",
    mode: "history",
    routes
  });
   /* 路由异常错误处理，尝试解析一个异步组件时发生错误，重新渲染目标页面 */
  // router.onError((error) => {
  //   console.log(error)
  //   const pattern = /Loading chunk (\d)+ failed/g;
  //   const isChunkLoadFailed = error.message.match(pattern);
  //   const targetPath = router.history.pending.fullPath;
  //   if (isChunkLoadFailed) {
  //     router.replace(targetPath);
  //   }
  // });
 
  instance = new Vue({
    router,
    store,
    render: h => h(App, { props: data })
  }).$mount("#app3");
}

export async function unmount() {
  instance.$destroy();
  instance = null;
  router = null;
}

console.log(window.__POWERED_BY_QIANKUN__)
// 单独开发环境
window.__POWERED_BY_QIANKUN__ || mount();